(function($){
	var hasScrollBar = false;
	var overflowY = null;
	var nowHeight = 0;
	var nowScrollTop = 0;
	
	$.extend({
		hasScrollBar: function(direction){
			if(direction == 'vertical'){
				return  $(document).height() > $(window).height();
			}else if(direction == 'horizontal'){
				return  $(document).width() > $(window).widths();
			}
		},
		openDocumentMask: function(objId){
			//scroll bar 控制
			if($.hasScrollBar('vertical') || $.hasScrollBar('vertical')){
				hasScrollBar = true;
				overflowY = $('body').css("overflow-y");
				scrollTop = $(document).scrollTop();
				nowHeight = $("#mainContentDiv").height();
			$('body').css({"overflow-y":"scroll"});
			$("#mainContentDiv").css({height:$(window).height()-20,'overflow-y':'hidden'})
														.scrollTop(scrollTop);
		}
			
			$('<div class="jquery_addmask"> </div>').appendTo(document.body).css({ 
				position: 'absolute', 
				top: '0px', 
				left: '0px', 
				'z-index': 100, 
				width: '100%', 
				height: $(document).height(), 
				'background-color': '#000', 
				opacity: 0 
			}).fadeIn('slow', function(){ 
				$(this).fadeTo('slow', 0.6); 
			}).click(function(){ 
				/*
					$(this).fadeTo('slow', 0, function(){ 
						$(this).remove(); 
					}); 
				*/
			});
			
			$("#"+objId).fadeTo('slow', 1);
			
			var screenwidth = $(window).width();
			var screenheight = $(window).height();
			var mytop = $(document).scrollTop();
			var getPosLeft = screenwidth/2 - $("#"+objId).width()/2;
			var getPosTop = screenheight/2 - $("#"+objId).height()/2;
			$("#"+objId).css({"position":"fixed",  "left":getPosLeft,"top":getPosTop});
			
			$(window).resize(function(){
				var screenwidth = $(window).width();
				var screenheight = $(window).height();
				var mytop = $(document).scrollTop();
				var getPosLeft = screenwidth/2 - $("#"+objId).width()/2;
				var getPosTop = screenheight/2 - $("#"+objId).height()/2;
				$("#"+objId).css({"left":getPosLeft,"top":getPosTop+mytop});
			});
			
			/*
			//下面部分代碼是讓彈出層，隨滾動條滾動而滾動，並始終居中； 此方法有一個缺憾就是彈出層隨滾動條滾動的時候有時候會輕微閃屏。建議在IE6下採用這段代碼，而FF Chrome等高級瀏覽器在CSS樣式裡面定義.tc_box 的定義為：position:fixed, 並設定left,top,margin等值。使其居中，這樣就只會在IE6下閃屏了。
			//附：IE6解決閃屏方法：body{ _background-image: url(about:blank);_background-attachment: fixed;}
			$(window).scroll(function(){
				screenwidth = $(window).width();
				screenheight = $(window).height();
				mytop = $(document).scrollTop();
				getPosLeft = screenwidth/2 - 200;
				getPosTop = screenheight/2 - 100;
				$("#"+objId).css({"left":getPosLeft,"top":getPosTop+mytop});
			});
			*/
		
			return this; 
		},
		closeDocumentMask: function(objId){
			$("#"+objId).fadeTo('slow', 0);
			$(".jquery_addmask").remove(); 
			
			//scroll bar 控制
			if(hasScrollBar){
				$('body').css({"overflow-y":overflowY});
				$("#mainContentDiv").css({height:nowHeight});
			$(document).scrollTop(scrollTop);
		}
		hasScrollBar = false;
		overflowY = null;
		nowHeight = 0;
		nowScrollTop = 0;
		
			return this; 
		}
	}); 
})(jQuery); 

		

/*
//打開遮罩 (註：diableObjName 為 Table/Form 物件，使該物件內的 select & input 失效，divName 為  Div 物件名稱，調整視窗大小時)
function showMask(diableObjName, divName){
	var divMask = document.getElementById('divMask');
	divMask.style.backgroundColor = '#000000';
	divMask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=50,finishOpacity=50);';//'alpha(opacity = 60)';
	divMask.style.opacity = '0.5';
	divMask.style.left = '0px';
	divMask.style.position = 'absolute';
	divMask.style.top = '0px';
	//為了讓遮罩在ie6中正常使用，故把select物件設為non-display，input物件設為disabled
	if( diableObjName!=null && diableObjName!="" ) {
		var selectRows = document.getElementById(diableObjName).getElementsByTagName('select');
		for (i=0; i<selectRows.length; i++) {
			selectRows[i].style.display = "none";
		}
		var inputRows = document.getElementById(diableObjName).getElementsByTagName('input');
		for (i=0; i<inputRows.length; i++) {
			inputRows[i].disabled="disabled";
		}
	}
	resizeMask(divName);
	//firefox 無法動作
	//window.onresize 代表視窗被調整大小時
	//window.onresize = resizeMask;
	//window.onscroll = resizeMask;  
}
//關閉遮罩 (註：enableObjName 為 Table/Form 物件，使該物件內的 select & input 有效)
function closeMask(enableObjName){
	var divMask = document.getElementById('divMask');
	divMask.style.width = "0px";
	divMask.style.height = "0px";
	//關閉遮罩時把select物件設為display，input物件設為enable
	if( enableObjName!=null && enableObjName!="" ) {
		var selectRows = document.getElementById(enableObjName).getElementsByTagName('select');
		for (i=0; i<selectRows.length; i++) {
			selectRows[i].style.display = "";
		}
		var inputRows = document.getElementById(enableObjName).getElementsByTagName('input');
		for (i=0; i<inputRows.length; i++) {
			inputRows[i].disabled="";
		}
	}
	//window.onresize = null;
	//Insert by 0395,20110919 for 避免mask關閉後，還會受到影響
	//window.onscroll = null;
}
//取得捲軸目前高度
function getScrollXY(){
	var scrX = 0, scrY = 0;
	if (typeof(window.pageYOffset) == 'number'){
		// Netscape
		scrY = window.pageYOffset;
		scrX = window.pageXOffset;
	}else if (document.body && (document.body.scrollLeft || document.body.scrollTop)){
		// DOM
		scrY = document.body.scrollTop;
		scrX = document.body.scrollLeft;
	}else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		// IE6
		scrY = document.documentElement.scrollTop;
		scrX = document.documentElement.scrollLeft;
	}
	return {x:scrX, y:scrY};
}
//視窗被調整大小時 (註：divName 為  Div 物件名稱，調整視窗大小時，重設 DIV 物件 x,y位置)
function resizeMask( divName ){
	var divMask = document.getElementById('divMask');
	if(document.documentElement.scrollWidth >= document.documentElement.clientWidth){
		divMask.style.width = document.documentElement.scrollWidth+"px";
	}else{
		divMask.style.width = document.documentElement.clientWidth+"px";
	}
	if(document.body.scrollHeight>=document.body.clientHeight){
		divMask.style.height = document.documentElement.scrollHeight+"px";
	}else{
		divMask.style.height = document.documentElement.clientHeight+"px";
	}
	maskDivPosition=getScrollXY();

	//Insert End, 20110919	
	if( divName!=null && divName!="" ) {
		if(document.getElementById(divName).style.display=="inline"){
			document.getElementById(divName).style.top=(document.documentElement.clientHeight-document.getElementById(divName).clientHeight)/2+maskDivPosition.y+"px";
			document.getElementById(divName).style.left=(document.documentElement.clientWidth-document.getElementById(divName).clientWidth)/2+maskDivPosition.x+"px";
		}
	}
}
*/